<?php
namespace app\home\controller;
use think\Controller;
use think\Db;
use think\Session;

class Login extends Controller
{
    public function index()
    {
        return $this->fetch();
    }

    public function login1()
    {
        $username=input('username');
        $password=input('password');
         $data=Db::table('user')->select();
         $result=Db::table('user')->where(['username'=>$username,'password'=>$password])->count();
         if($result>0)
         {
            Session::set('username',$username);
            $this->success('登陆成功','User/index');
         }
            
        else
            $this->error('登录失败');

    }
    public function login2()
    {
        $username=input('username');
        $password=input('password');
        $data=Db::table('user')->select();
         $result=Db::table('user')->where(['username'=>$username,'password'=>$password])->count();
         if($result>0)
         {
            Session::set('username',$username);
           return ['status'=>1,'message'=>'登陆成功'];
         }
            
        else
            return ['status'=>0,'message'=>'登陆失败'];

    }
    public function res()
    {
        return $this->fetch();
    }
    public function respass()
    {
        $username=input('username');
        $password=input('password');
        $data['username']=$username;
        $data['password']=$password;
        $repassword=input('repassword');
        if($password!=$repassword)
            $this->error('两次输入密码不一致','res');
        else
        {
            $result=Db::table('user')->insert($data);
            if($result)
                $this->success('注册成功','index');
            else
                $this->success('注册失败');
        }
    }

}